// Source : https://leetcode.com/problems/two-sum/
// Author : simba
// Date   : 2016-06-07

package main

import (
	"fmt"
)

func twoSum(nums []int, target int) []int {
	res := make([]int, 2)
	for i, j := 0, len(nums)-1; i < j; i++ {
		for ii := i + 1; ii < j+1; ii++ {
			if nums[i]+nums[ii] == target {
				res[0] = i
				res[1] = ii
				return res
			}
		}
	}
	res[0] = -1
	res[1] = -1
	return res
}

func main() {
	//固定测试用例,正确答案[1 2]
	s1 := []int{3, 2, 4}
	t1 := 6
	a1 := twoSum(s1, t1)
	fmt.Println("数组", s1)
	fmt.Println("目标数", t1)
	fmt.Println("输出答案", a1)
	fmt.Println("正确答案[1 2]")

	//固定测试用例,正确答案[0 3]
	s3 := []int{0, 4, 3, 0}
	t3 := 0
	a3 := twoSum(s3, t3)
	fmt.Println("数组", s3)
	fmt.Println("目标数", t3)
	fmt.Println("输出答案", a3)
	fmt.Println("正确答案[0 3]")

	//固定测试用例,正确答案[0 2]
	s4 := []int{-3, 4, 3, 90}
	t4 := 0
	a4 := twoSum(s4, t4)
	fmt.Println("数组", s4)
	fmt.Println("目标数", t4)
	fmt.Println("输出答案", a4)
	fmt.Println("正确答案[0 2]")
}
